from rest_framework.authentication import BaseAuthentication
from . import models


class TokenAuthentication(BaseAuthentication):
    def authenticate(self, request):
        token = request.query_params.get('token')
        user_obj = models.UserInfo.objects.filter(token=token).first()
        if user_obj:
            return (user_obj, token)
        return (None, None)